#!/bin/sh

. ./VERSION
DISTRIB=../staff_tmp$(printf %x $(date +%s))/
REVISION=$(LANG=en svn info --non-interactive 2>&- | grep 'Revision: ' | cut -d' ' -f2)
TARBALLNAME=../staff-src-${PACKAGE_VERSION}-r${REVISION}

test $(svn st --non-interactive | grep -vE '^\? ' | wc -l) -eq 0 || \
    /bin/echo -e "\e[1mWARNING: working copy has local changes\e[0m"

echo "creating tarball..."

rm -Rf ${DISTRIB}
mkdir -p ${DISTRIB}staff/
cp -Rf . ${DISTRIB}staff/
cd ${DISTRIB}staff/

make distclean >/dev/null
rm -f staff.creator.user create_src_tarball update_qtcreator_files
svn st . --no-ignore | sed -n '/^[I\?]/s/^.[ \t]*//p' | xargs rm -rf
find -type d -name .svn | xargs rm -Rf
cd ..

if [ -z "$(which 7z)" ]
then
  tar c staff | bzip2 >${TARBALLNAME}.tar.bz2
  rm -Rf ${DISTRIB}
  echo "created ${TARBALLNAME}.tar.bz2"
else
  7z a -r $@ ${TARBALLNAME}.7z staff
  rm -Rf ${DISTRIB}
  echo "created ${TARBALLNAME}.7z"
fi

